<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">




<title>ie6，7 location.href 没有权限的出现原因及解决方案 - 飘~ - 博客园</title>




<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/WuQiang/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/WuQiang/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/WuQiang/wlwmanifest.xml">
  

 





<link rel="stylesheet" type="text/css" href="index.css" media="all">
</head>
<body><div id="home"><div id="main"><div id="mainContent">
	<div class="forFlow">
		<!--end: navigator 博客导航栏 -->
		
	
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/WuQiang/archive/2012/09/21/2697474.html">ie6，7 location.href 没有权限的出现原因及解决方案</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body"><div><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255); display: inline ! important; float: none;">
<div><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255); display: inline ! important; float: none;">&nbsp;&nbsp;&nbsp;&nbsp; QA 给我提了个bug，说是页面在ie7下点击切换语言报了个js错误。于是在办公网配上开发机host便用ie8的ie7模式看了下，一切正常，到qa同事机器看了下，确 实报js错误。。。看来只有纯ie7才会有这个问题。回到座位开启虚拟机，用ie7试了下首页，果然可以重现， permission declined。以下是切换语言代码：</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
</span>
<div class="cnblogs_code">
<div><div><span style="color: rgb(0, 0, 255);">if</span>&nbsp;(lang&nbsp;&amp;&amp;&nbsp;lang&nbsp;!==&nbsp;__Config.current_lang&nbsp;&amp;&amp;&nbsp;lists[lang]){&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(0, 0, 255);">var</span>&nbsp;reg_lang&nbsp;=&nbsp;/(&amp;|\?)(lang=)[^&amp;]*(&amp;|$)/g;&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location.href&nbsp;=&nbsp;(location.href.replace(reg_lang,&nbsp;'$1').replace(/#.*$/,'')&nbsp;+&nbsp;'&amp;lang='&nbsp;+&nbsp;lang).replace(/&amp;+/g,&nbsp;'&amp;').replace(/\/&amp;/,'/?');&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</div></div>
</div>
</div>
<div><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255); display: inline ! important; float: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看了下唯一可能出问题的就是location.href这里，去掉</span><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(250, 250, 250);">location.href = (location.href.replace(reg_lang, '$1').replace(/#.*$/,'') + '&amp;lang=' + lang).replace(/&amp;+/g, '&amp;').replace(/\/&amp;/,'/?');果然没有报错了。这就奇怪了，首页就在顶级域名xx</span><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(250, 250, 250);">.com</span><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(250, 250, 250);">下，没有任何跨域的可能。于是新建了一个测试页面把代码贴进去，一切正常。。。那究竟是哪里出问题呢，回头继续看代码，首页为了增加feedback，弄了个iframe把feedback.xx.com下一个页面加载进来，而该页面在提交feedback成功后会调用父页面的关闭弹出层方法，由于跨域原因父页面与该子页面都加入了document.domain='xx.com'这句，而这句正是与测试页面不同的地方，于是乎在首页试着把</span><span style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(250, 250, 250);">document.domain='xx.com'去掉，语言切换正常了，但feedbak子页面提交后弹出层不能关闭了，由于跨域。猜想在测试页面加上document.domain='xx.com'应该也会报没权限吧，试了下结果竟然还是正常。。。还有什么不同？？？难道是jquery？测试页面没有引入，抱着试试看的态度把jquery 1.71加进去，wow，测试页面终于报错了。坑爹啊，jquery究竟做了什么？网上找了几乎没啥资料，总不能让我把jquery从首页去掉吧，实在没有头绪，这个切换语言必须要获取当前页面url才能做。接着再试，发现在主页设置documen.domain之前是可以获取到location.href的，这样看起来还不错，那在设置domain后不能读，是否可以设置呢？试了下ok，这样的话不完美解决方案产生了，在设置domain前先用个变量存储当前页面url，在设置的时候直接用，这样可以避开ie 7 location.href的读取权限问题。</span></div><p>&nbsp;</p>
<div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 想了下如果页面的hash变了，而hash的改变并不会刷新页面，这样我之前获取的url就不准确了，肿么办？不知道，郁闷中抄起一根精白沙走到了吸烟区，点上，慢慢踱步，是不是还有其他方法获取当前页面url呢？突然灵光一现，document.URL是不是可以呢？狠狠的掐灭烟头，奔回座位在测试页面试了下没报脚本错误，顺利取到了当前页面url。</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);"><br>
</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);">&nbsp; &nbsp; &nbsp;&nbsp;<strong>总结如下：</strong></span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);">&nbsp; &nbsp; &nbsp; 在ie6，7页面下如果设置domain如与当前域相同，且引入了jquery（我试了1.4.2, 1.7.1, 1.8.1）取location.href会报没有权限的错误。</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);"><br>
</span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);">&nbsp; &nbsp; &nbsp;&nbsp;<strong>解决方案：</strong></span></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(250, 250, 250);">&nbsp; &nbsp; &nbsp; 用documen.URL代替（</span>document.URL 取值时等价于 window.location.href 或 document.location.href。在某些浏览器中通过对 document.URL 赋值来实现页面跳转，但某些浏览器中不行）。</div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"></div>
<div style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">&nbsp;</div><p>最后附上几段测试代码，测试环境虚拟机中，ie6,7</p>

<div><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">成功，设置domain，引入jquery，用document.URL，用document.URL在下面几种情况都ok；</strong></div><div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div>
<div><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="text/html;&nbsp;charset=utf-8"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="button"</span><span style="color: rgb(255, 0, 0);">&nbsp;value</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;onclick</span><span style="color: rgb(0, 0, 255);">="test()"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script&nbsp;</span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">="http://www.xx.com/wechat_portal/js/jquery.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;&nbsp;<br>
document.domain&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">xx.com</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">function</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;test()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">test</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">).value&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;document.URL;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;</div>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div></div>
<p><br></p>
</div><div><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">失败, 设置domain，引入jquery，用location.href；</strong></div>
<div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div>
<div><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="text/html;&nbsp;charset=utf-8"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="button"</span><span style="color: rgb(255, 0, 0);">&nbsp;value</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;onclick</span><span style="color: rgb(0, 0, 255);">="test()"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script&nbsp;</span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">="http://www.xx.com/wechat_portal/js/jquery.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;&nbsp;<br>
document.domain&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">xx.com</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">function</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;test()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">test</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">).value&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;location.href;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;</div>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<div><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">成功，设置domain，不引入jquery，用location.href；</strong></div>
<div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div>
<div><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="text/html;&nbsp;charset=utf-8"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="button"</span><span style="color: rgb(255, 0, 0);">&nbsp;value</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;onclick</span><span style="color: rgb(0, 0, 255);">="test()"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;&nbsp;<br>
document.domain&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">xx.com</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">function</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;test()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">test</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">).value&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;location.href;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br>
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br>
<span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div></div>
<div>&nbsp;</div><p><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">成功，不设置</strong><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);"><strong style="color: rgb(0, 0, 0); font-family: Tahoma,Verdana,Lucida,Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(255, 255, 255);">domain</strong></strong>，<strong>引入jquery，用location.href; </strong><br></p><div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div><div><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="text/html;&nbsp;charset=utf-8"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="button"</span><span style="color: rgb(255, 0, 0);">&nbsp;value</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;onclick</span><span style="color: rgb(0, 0, 255);">="test()"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script&nbsp;</span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">="http://www.xx.com/js/jquery.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">function</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;test()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">test</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">'</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">).value&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;location.href;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;&nbsp;<br><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span>&nbsp;</div><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="copycode.gif" alt="复制代码"></a></span></div></div></div><div id="MySignature"></div>

<div class="clear"></div>


		</div>
		
	</div>
	<img src="2697474.html" alt="" height="1" width="1">
	
</div><!--end: topics 文章、评论容器-->

<div id="comment_form" class="commentform">
<div id="divCommentShow"></div>

<div id="comment_form_container"></div>





<div id="ad_under_post_holder">

<div id="blog_news_kb"></div>
</div>
<div id="HistoryToday" class="c_ad_block"></div>
</div>





	</div><!--end: forFlow -->
	</div></div></div></body>
</html>
